import time
from selenium.webdriver.common.by import By
from common.Utils import ForumDriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys


class ForumperCenter:
    driver = ""
    def __init__(self):
        self.driver = ForumDriver.driver

    def PerCebterPageelements(self):
        #在论坛页面的基础上
        self.driver.find_element(By.CSS_SELECTOR, "#index_nav_avatar").click()
        # 点击个人中心
        self.driver.find_element(By.CSS_SELECTOR,"#index_user_settings").click()
        time.sleep(1)
        #检查用户头像
        self.driver.find_element(By.CSS_SELECTOR,"#settings_avatar")
        #检查用户框并且打印出用户昵称
        text1 = self.driver.find_element(By.CSS_SELECTOR,"#setting_input_nickname").text
        print("用户昵称："+text1)
        #检查用户的邮箱并且打印出用户邮箱
        text2 = self.driver.find_element(By.CSS_SELECTOR, "#setting_input_email").text
        print("用户邮箱：" + text2)
        #检查用户的电话号码并且打印出用户电话号码
        text3 = self.driver.find_element(By.CSS_SELECTOR, "#setting_input_phoneNum").text
        print("用户邮箱：" + text3)
        #检查原密码输入框
        self.driver.find_element(By.CSS_SELECTOR,"#settings_input_oldPassword")
        #检查新密码输入框
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_newPassword")
        #检查确认密码输入框
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_passwordRepeat")
        #检查个人简介框
        text4 = self.driver.find_element(By.CSS_SELECTOR, "#settings_textarea_remark").text

    # 测试修改密码功能
    def PerCenterPageFunctions(self):
    #     #不输入原密码，输入新密码和确认密码
    #     # 在论坛页面的基础上
    #     self.driver.find_element(By.CSS_SELECTOR, "#index_nav_avatar").click()
    #     # 点击个人中心
    #     self.driver.find_element(By.CSS_SELECTOR, "#index_user_settings").click()
    #     time.sleep(1)
    #     # 检查原密码输入框
    #     input_element = self.driver.find_element(By.CSS_SELECTOR, "#settings_input_oldPassword")
    #     action = ActionChains(self.driver)
    #     action.click(input_element).send_keys(Keys.RETURN).perform()
    #     # 检查新密码输入框
    #     self.driver.find_element(By.CSS_SELECTOR, "#settings_input_newPassword").send_keys("123456")
    #     # 检查确认密码输入框
    #     self.driver.find_element(By.CSS_SELECTOR, "#settings_input_passwordRepeat").send_keys("123456")
    #     self.driver.find_element(By.CSS_SELECTOR,"#settings_submit_password").click()
    #     time.sleep(1)
    #     ForumDriver.GetScreeShot()

        # # 输入原密码，不输入新密码和输入确认密码
        # # 在论坛页面的基础上
        # self.driver.find_element(By.CSS_SELECTOR, "#index_nav_avatar").click()
        # # 点击个人中心
        # self.driver.find_element(By.CSS_SELECTOR, "#index_user_settings").click()
        # time.sleep(1)
        # # 检查原密码输入框
        # self.driver.find_element(By.CSS_SELECTOR, "#settings_input_oldPassword").send_keys("1234567")
        # # 检查新密码输入框
        # self.driver.find_element(By.CSS_SELECTOR, "#settings_input_newPassword")
        # # 检查确认密码输入框
        # self.driver.find_element(By.CSS_SELECTOR, "#settings_input_passwordRepeat").send_keys("123456")
        # self.driver.find_element(By.CSS_SELECTOR, "#settings_submit_password").click()
        # time.sleep(1)
        # ForumDriver.GetScreeShot()

        # # 输入原密码，输入新密码和不输入确认密码
        # # 在论坛页面的基础上
        # self.driver.find_element(By.CSS_SELECTOR, "#index_nav_avatar").click()
        # # 点击个人中心
        # self.driver.find_element(By.CSS_SELECTOR, "#index_user_settings").click()
        # time.sleep(1)
        # # 检查原密码输入框
        # self.driver.find_element(By.CSS_SELECTOR, "#settings_input_oldPassword").send_keys("1234567")
        # # 检查新密码输入框
        # self.driver.find_element(By.CSS_SELECTOR, "#settings_input_newPassword").send_keys("123456")
        # # 检查确认密码输入框
        # self.driver.find_element(By.CSS_SELECTOR, "#settings_input_passwordRepeat")
        # self.driver.find_element(By.CSS_SELECTOR, "#settings_submit_password").click()
        # time.sleep(1)
        # ForumDriver.GetScreeShot()

        #输入正确的原密码，输入新密码和输入与新密码一样的确认密码
        # 在论坛页面的基础上
        self.driver.find_element(By.CSS_SELECTOR, "#index_nav_avatar").click()
        # 点击个人中心
        self.driver.find_element(By.CSS_SELECTOR, "#index_user_settings").click()
        time.sleep(1)
        # 检查原密码输入框
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_oldPassword").send_keys("123456")
        # 检查新密码输入框
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_newPassword").send_keys("1234567")
        # 检查确认密码输入框
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_passwordRepeat").send_keys("1234567")
        open = self.driver.find_element(By.CSS_SELECTOR, "#settings_submit_password")
        action = ActionChains(self.driver)
        time.sleep(1)
        action.move_to_element(open).click().perform()
        time.sleep(3)
        ForumDriver.GetScreeShot()
        title = self.driver.title
        url = self.driver.current_url
        print("修改密码后的标签页："+title)
        print("修改密码后的url："+url)

